﻿using System;
using System.ComponentModel.Composition;
using System.Reflection;
using AlanAamy.Net.TemperatureConverter.Infrastructure.Constants;
using AlanAamy.Net.TemperatureConverter.Infrastructure.Frameworks.RX;
using log4net;

namespace AlanAamy.Net.TemperatureConverter.Models
{
    public interface ILeftSequenceObserverModel
    {
        IObservable<Decimal> GetObservable();
        TemperatureUnit Unit { get; set; }
        Decimal Value { get; set; }
        void ToggleUnit();
        event EventHandler ValueChanged;
        event EventHandler UnitChanged;
    }

    [Export(typeof(ILeftSequenceObserverModel))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class LeftSequenceObserverModel : ObservableSequence<Decimal,TemperatureUnit>,  ILeftSequenceObserverModel
    {
        private static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        
        [ImportingConstructor]
        public LeftSequenceObserverModel()
        {
            Value = 1.0M;
            Unit = TemperatureUnit.Celsius;
        }

        public void ToggleUnit()
        {
            Unit = 1 - Unit;
            Log.Debug("Unit Toggled to " + Unit);
        }

    }
}
